package com.main.hotel.controller;

import com.main.hotel.entity.Bill;
import com.main.hotel.entity.OrderInfo;
import com.main.hotel.entity.Room;
import com.main.hotel.service.BillService;
import com.main.hotel.service.OrderInfoService;
import com.main.hotel.service.RoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
/**
* @author 莫浚洋
*/
//入住登记和结账退房
@Controller
public class CheckinController {
    @Autowired
    private RoomService roomService;
    @Autowired
    private OrderInfoService orderInfoService;

    @Autowired
    private BillService billService;


    //显示房间
    @RequestMapping(value = "checkin/findall",method = RequestMethod.GET)
    @ResponseBody
    public Page<Room> findAllRoomType(Integer page, HttpServletResponse response){
        response.setHeader("Access-Control-Allow-Origin","*");
        if(page==null||page<=0){
            page=0;
        }else{
            page-=1;
        }
        return roomService.findAll(page,3);
    }

    //显示预订订单信息
    @RequestMapping(value = "checkin/findallorder",method = RequestMethod.GET)
    @ResponseBody
    public Page<OrderInfo> findAllOrderInfo(Integer page1, HttpServletResponse response){
        response.setHeader("Access-Control-Allow-Origin","*");
        if(page1==null||page1<=0){
            page1=0;
        }else{
            page1-=1;
        }

        return orderInfoService.findAll(page1,3);
    }

    //显示BILL信息
    @RequestMapping(value = "checkin/findallbill",method = RequestMethod.GET)
    @ResponseBody
    public Page<Bill> findAllBill(Integer page2, HttpServletResponse response){
        response.setHeader("Access-Control-Allow-Origin","*");
        if(page2==null||page2<=0){
            page2=0;
        }else{
            page2-=1;
        }
        System.out.println(555);
        return billService.findAll(page2,3);
    }
    //业务统计
    @RequestMapping(value = "checkin/statistics")
    @ResponseBody
    public String statistics () {
        Integer checkInNum = orderInfoService.findTotalMember();
        Long money = billService.findTotalCost();
        return "总入住人数：" + checkInNum + "总收入：" + money;
    }

/*  @RequestMapping(value = "check/checkIn")
@ResponseBody
  public String checkIn(String order_id) {
      int r1=orderInfoService.updateOrder2(order_id);
      OrderInfo orderInfo=orderInfoService.getOrderById(order_id);
Bill bill=new Bill();
int customer_id=orderInfo.getFoo();
int room_id=orderInfo.getRoom_id();
float cost=orderInfo.getOrder_cost();
bill.setCost(cost);
bill.setCustomer_id(customer_id);
bill.setRoom_id(room_id);
int r2=billService.addBill(bill);
String roomNum=roomService.findRoomNum(order_id);
return roomNum;

  }*/
}
